package com.sgai.dcac.ui.activity;

import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.TextView;

import com.sgai.dcac.R;
import com.sgai.dcac.ui.common.BaseActivity;

public class SplashActivity extends BaseActivity {

    private static final String TAG = "MainActivity";
    private Thread thread;
    private TextView textView;

    @Override
    protected void findViewById() {
        textView = (TextView) findViewById(R.id.textView);
    }

    @Override
    protected void setUpView() {
        delay();
    }

    @Override
    protected int getContentView() {
        return R.layout.activity_splash;
    }

    private void delay () {
        thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    for (int i = 0; i < 5; i++) {
                        handler.sendEmptyMessage(5-i);
                        Thread.sleep(1000);
                        Log.i(TAG,(i+1)+"秒");
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //start main Activity
                MainActivity.startThisActivity(SplashActivity.this);
            }
        });
        thread.start();
    }

    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            textView.setText(msg.what+"秒");
        }
    };
}
